package thread;

import java.util.Scanner;

/**
 * 线程提供了一个静态方法
 * static void sleep(long ms)
 * 当一个线程调用sleep后就会进入阻塞状态指定的毫秒。超过后线程会自动回到RUNNABLE状态
 * 再次开始并发运行
 * <p>
 * sleep：睡觉，睡眠
 */
public class SleepDemo {
    public static void main(String[] args) {
        System.out.println("程序开始了！");

      /*  try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("程序结束了！");*/

        /*System.out.println("请输入你想倒计时的秒数：");
        int s = new Scanner(System.in).nextInt();
        System.out.println("倒计时开始：");
        while (true) {
            if (s==0)break;
            System.out.println(s);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                s--;
            }
        }
        System.out.println("倒计时结束");*/
        try {
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入一个数字：");
            for (int num = scanner.nextInt(); num > 0; num--) {
                System.out.println(num);
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("时间到！");
    }
}
